#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <string.h>

//https://leetcode.cn/problems/intersection-of-two-arrays/submissions/

int cmpare(const void *A, const void *B) {
    return *(int *)A - *(int *)B;
}

int *intersection(int *nums1, int nums1Size, int *nums2, int nums2Size, int *returnSize) {
    qsort(nums1, nums1Size, sizeof(int), cmpare);     //快速排序
    qsort(nums2, nums2Size, sizeof(int), cmpare);
    int *ret = malloc(sizeof(int) * (nums1Size + nums2Size));
    int *left1 = nums1;         //指针1
    int *left2 = nums2;         //指针2
    *returnSize = 0;
    int index1 = 0;
    int index2 = 0;
    while (index1 < nums1Size && index2 < nums2Size) {        //如果
        if (left1[index1] == left2[index2]) {
            if (*returnSize == 0 || ret[*returnSize - 1] != left1[index1]) {
                ret[*returnSize] = left1[index1];
                (*returnSize)++;
            }
            index1++;
            index2++;
        } else {
            left1[index1] < left2[index2] ? index1++ : index2++;
        }
    }
    return ret;
}

int main() {

    return 0;
}